package com.runshu.newsmartark.activity;

import android.os.Handler;
import android.text.TextUtils;
import android.view.Window;
import android.view.WindowManager;

import com.runshu.newsmartark.R;
import com.runshu.newsmartark.base.BaseActivity;
import com.runshu.newsmartark.base.MyApplication;
import com.runshu.newsmartark.common.ConstantUrl;
import com.runshu.newsmartark.entity.HDInfoBean;
import com.runshu.newsmartark.entity.HwInfoUtils;
import com.runshu.newsmartark.mvp.contract.MainHomeContract;
import com.runshu.newsmartark.mvp.model.MainHomeModel;
import com.runshu.newsmartark.mvp.presenter.MainHomePresenter;
import com.runshu.newsmartark.network.netbean.ResponseBean;
import com.runshu.newsmartark.util.LodDialogClass;
import com.runshu.newsmartark.util.MacUtils;
import com.runshu.newsmartark.util.common.SharedPreferencesUtils;

/**
 * Demo class
 *
 * @author yu
 * @date 2021/12/13
 * @decs：
 */

public class SplashActivity extends BaseActivity implements MainHomeContract.View {
    private MainHomePresenter homePresenter;

    @Override
    protected int getLayoutId() {
        //取消状态栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //设置为全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);


        return R.layout.act_splash;
    }

    @Override
    protected void initView() {
        homePresenter = new MainHomePresenter(this, new MainHomeModel());
    }

    @Override
    protected void initData() {
        goToMain();
    }

    @Override
    protected void bindListener() {

    }

    private void goToMain() {
        boolean isFirst = (boolean) SharedPreferencesUtils.get(MyApplication.getApplication(), ConstantUrl.Share_LoadingFirst, true);
        if (isFirst) {
            LodDialogClass.showCustomCircleProgressDialog(context);
            LodDialogClass.setCustomCircleProgressDialogHintText("初始化数据中...");
            homePresenter.getHdInfo( MacUtils.getFormatMacAddr());
        }else {
            startActivity(NewMainactivity.class);
            finish();
        }
        SharedPreferencesUtils.put(MyApplication.getApplication(), ConstantUrl.Share_LoadingFirst, false);

    }

    @Override
    protected void afterRequestPermission(int requestCode, boolean isAllGranted) {

    }

    @Override
    public void getIndexCount(ResponseBean responseBean) {

    }

    @Override
    public void getHdInfoSuccess(ResponseBean responseBean) {
        HDInfoBean hdInfoBean = (HDInfoBean) responseBean.pullData();
        HwInfoUtils.saveData(context, hdInfoBean);
        LodDialogClass.closeCustomCircleProgressDialog();
        startActivity(NewMainactivity.class);
        finish();
    }

    @Override
    public void getInventorySumSuccess(ResponseBean responseBean) {

    }
}